package com.xiaoshuidi.cloud.module.contract.controller.admin.contract;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.ContractFixedFeeVo;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.OrderLateFeeVo;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.ContractFixedFeeService;
import com.xiaoshuidi.cloud.module.system.api.apartment.ApartmentManageApi;
import com.xiaoshuidi.cloud.module.system.enums.apartment.ApartmentManageEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import jodd.util.StringUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @BelongsProject: lease-module-contract
 * @BelongsPackage: com.xiaoshuidi.cloud.module.contract.controller.admin.contract
 * @Author: James
 * @CreateTime: 2023-11-15  09:40
 * @Description: 合同延期退配置
 * @Version: 1.0
 */
@Slf4j
@Tag(name = "账单配置 - 合同延期配置")
@RestController
@RequestMapping(ApiConstants.NAME + "/contractFiexdFee")
@RequiredArgsConstructor
public class ContractFiexdFeeController {
    @Resource
    private ContractFixedFeeService contractFixedFeeService;
    @Resource
    private ApartmentManageApi apartmentManageApi;

    /*
     * @description:查询合同延期配置
     * @author: James
     * @date: 2023/11/15 11:17
     * @param: [apartmentId]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<com.xiaoshuidi.cloud.module.contract.dal.dataobject.contract.ContractFixedFeeVo>
     **/
    @GetMapping("/getContractFiexdFee")
    public CommonResult<ContractFixedFeeVo>getContractFiexdFee(Long apartmentId){
        return CommonResult.success(contractFixedFeeService.getContractFiexdFee(apartmentId));
    }
    /*
     * @description:修改合同延期配置
     * @author: James
     * @date: 2023/11/15 11:23
     * @param: [contractFixedFeeVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<java.lang.Boolean>
     **/
    @PostMapping("/updateContractFiexdFee")
    public CommonResult<Boolean> updateContractFiexdFee(ContractFixedFeeVo contractFixedFeeVo){
        if(contractFixedFeeVo.getIsFixedFee()){
            contractFixedFeeVo.setRoomRate(null);
        }
        if(contractFixedFeeVo.getIsRoomRate()){
            contractFixedFeeVo.setFixedFee(null);
        }
        return CommonResult.success(contractFixedFeeService.updateContractFiexdFee(contractFixedFeeVo));
    }

    /**
     * POst 请求
     * @param contractFixedFeeVo
     * @return
     */
    @PostMapping("/saveFiexdFee")
    public CommonResult<Boolean> saveFiexdFee(@RequestBody ContractFixedFeeVo contractFixedFeeVo){
        if(contractFixedFeeVo.getIsFixedFee()){
            contractFixedFeeVo.setRoomRate(null);
        }
        if(contractFixedFeeVo.getIsRoomRate()){
            contractFixedFeeVo.setFixedFee(null);
        }
        return CommonResult.success(contractFixedFeeService.updateContractFiexdFee(contractFixedFeeVo));
    }
    /*
     * @description:新增合同延期配置
     * @author: James
     * @date: 2023/11/15 11:25
     * @param: [ContractFixedFeeVo]
     * @return: com.xiaoshuidi.cloud.framework.common.pojo.CommonResult<java.lang.Boolean>
     **/
    @PostMapping("/insertContractFiexdFee")
    public CommonResult<Boolean>insertContractFiexdFee(ContractFixedFeeVo contractFixedFeeVo){
        apartmentManageApi.updateApartment(contractFixedFeeVo.getApartmentId(), ApartmentManageEnum.CONTRACT_CONFIG.getCode());
        return CommonResult.success(contractFixedFeeService.save(contractFixedFeeVo));
    }

}
